<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script type="module">
    // 地图
    // import { Domain } from "./js/map.js"
    // let map = new Domain()
    // 方块
    // import { Rect } from "./js/Rect.js"
    // let d1 = new Rect(0, 0, "red")
    // 蛇
    import { Snake } from "./js/snake.js"
    let snake = new Snake();
    document.onkeydown = function (e) {
      switch (e.key) {
        case "w":
          if (snake.dir !== "down") {
            snake.dir = "up";
          }
          break;
        case "a":
          if (snake.dir !== "right") {
            snake.dir = "left";
          }
          break;
        case "s":
          if (snake.dir !== "up") {
            snake.dir = "down";
          }
          break;
        case "d":
          if (snake.dir !== "left") {
            snake.dir = "right";
          }
          break;
      }
    }
  </script>
</body>

</html>